#include "ThreadBase.h"
#include "ClientInformation.h"
#include "GlobalDefinition.h"
#include "CircleDequeueBase.h"
#include "IOCPDefinition.h"
#include <map>
#include <string>

using namespace std;
const unsigned int TIME_LIMIT = 20;			// 20 seconds
const unsigned int TIMEOUT_LIMIT = 2*60;	// 2 minutes

class ThreadHeartBeat : public ThreadBase
{
public:
	ThreadHeartBeat(ConnectionInformation* p_pclsClients, map<int,CircleDequeueBase*> p_mapCircleQueue);
	//~ThreadHeartBeat();

protected:
	virtual void Run();

private:
	//static void CALLBACK TimeProc(HWND hwnd,UINT message,UINT iTimerID,DWORD dwTime);

	bool SendTestPacket(SOCKET p_iClient);
	void RemoveClient(SOCKET p_iClient);
	char* GetBufferFromMemoryPool(unsigned int p_uilength, unsigned int p_uiIndex);
	PER_IO_CONTEXT* GetNewIOConetext(char* p_szBuffer, unsigned int p_uiBufferLength, OPERATION_TYPE p_eType, SOCKET p_stSocket, bool p_bNeedRelease);
	void CleanUpServer();

private:
	ConnectionInformation* m_pclsClients;
	map<int,CircleDequeueBase*> m_mapCircleQueue;
	unsigned int m_uiCurrentID;
};